(function () {
    var s, i, l, d, f, n, r, c = true;
    k();
    j();
    a();

    function k() {
        s = window.innerWidth;
        i = window.innerHeight;
        r = {x: s / 2, y: i / 2};
        l = document.getElementById("large-header");
        l.style.height = i + "px";
        d = document.getElementById("demo-canvas");
        d.width = s;
        d.height = i;
        f = d.getContext("2d");
        n = [];
        for (var G = 0; G < s; G = G + s / 20) {
            for (var H = 0; H < i; H = H + i / 20) {
                var E = G + Math.random() * s / 20;
                var F = H + Math.random() * i / 20;
                var A = {x: E, originX: E, y: F, originY: F};
                n.push(A)
            }
        }
        for (var v = 0; v < n.length; v++) {
            var u = [];
            var B = n[v];
            for (var w = 0; w < n.length; w++) {
                var C = n[w];
                if (!(B == C)) {
                    var D = false;
                    for (var z = 0; z < 5; z++) {
                        if (!D) {
                            if (u[z] == undefined) {
                                u[z] = C;
                                D = true
                            }
                        }
                    }
                    for (var z = 0; z < 5; z++) {
                        if (!D) {
                            if (h(B, C) < h(B, u[z])) {
                                u[z] = C;
                                D = true
                            }
                        }
                    }
                }
            }
            B.closest = u
        }
        for (var v in n) {
            var t = new e(n[v], 2 + Math.random() * 2, "rgba(255,255,255,0.3)");
            n[v].circle = t
        }
    }

    function a() {
        if (!("ontouchstart" in window)) {
            window.addEventListener("mousemove", m)
        }
        window.addEventListener("scroll", p);
        window.addEventListener("resize", o)
    }

    function m(t) {
        var u = posy = 0;
        if (t.pageX || t.pageY) {
            u = t.pageX;
            posy = t.pageY
        } else {
            if (t.clientX || t.clientY) {
                u = t.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
                posy = t.clientY + document.body.scrollTop + document.documentElement.scrollTop
            }
        }
        r.x = u;
        r.y = posy
    }

    function p() {
        if (document.body.scrollTop > i) {
            c = false
        } else {
            c = true
        }
    }

    function o() {
        s = window.innerWidth;
        i = window.innerHeight;
        l.style.height = i + "px";
        d.width = s;
        d.height = i
    }

    function j() {
        b();
        for (var t in n) {
            q(n[t])
        }
    }

    function b() {
        if (c) {
            f.clearRect(0, 0, s, i);
            for (var t in n) {
                if (Math.abs(h(r, n[t])) < 4000) {
                    n[t].active = 0.3;
                    n[t].circle.active = 0.6
                } else {
                    if (Math.abs(h(r, n[t])) < 20000) {
                        n[t].active = 0.1;
                        n[t].circle.active = 0.3
                    } else {
                        if (Math.abs(h(r, n[t])) < 40000) {
                            n[t].active = 0.02;
                            n[t].circle.active = 0.1
                        } else {
                            n[t].active = 0;
                            n[t].circle.active = 0
                        }
                    }
                }
                g(n[t]);
                n[t].circle.draw()
            }
        }
        requestAnimationFrame(b)
    }

    function q(t) {
        TweenLite.to(t, 1 + 1 * Math.random(), {
            x: t.originX - 50 + Math.random() * 100,
            y: t.originY - 50 + Math.random() * 100,
            ease: Circ.easeInOut,
            onComplete: function () {
                q(t)
            }
        })
    }

    function g(u) {
        if (!u.active) {
            return
        }
        for (var t in u.closest) {
            f.beginPath();
            f.moveTo(u.x, u.y);
            f.lineTo(u.closest[t].x, u.closest[t].y);
            f.strokeStyle = "rgba(156,217,249," + u.active + ")";
            f.stroke()
        }
    }

    function e(v, w, u) {
        var t = this;
        (function () {
            t.pos = v || null;
            t.radius = w || null;
            t.color = u || null
        })();
        this.draw = function () {
            if (!t.active) {
                return
            }
            f.beginPath();
            f.arc(t.pos.x, t.pos.y, t.radius, 0, 2 * Math.PI, false);
            f.fillStyle = "rgba(156,217,249," + t.active + ")";
            f.fill()
        }
    }

    function h(t, u) {
        return Math.pow(t.x - u.x, 2) + Math.pow(t.y - u.y, 2)
    }
})();